﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
//using Microsoft.Expression.Interactivity.Core;

namespace ProbabilityNot
{
    /// <summary>
    /// Will select all the text in a textbox when it gets focus.
    /// </summary>
	public class SelectTextOnEntry : Behavior<TextBox>
	{
		public SelectTextOnEntry()
		{
		}

        /// <summary>
        /// Wire up the focus event
        /// </summary>
		protected override void OnAttached()
		{
			base.OnAttached();

            AssociatedObject.GotFocus += new RoutedEventHandler(AssociatedObject_GotFocus);
		}

        /// <summary>
        /// We have just gotten the focus. Select it all!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AssociatedObject_GotFocus(object sender, RoutedEventArgs e)
        {
            AssociatedObject.SelectAll();
        }

        /// <summary>
        /// Disconnect now.
        /// </summary>
		protected override void OnDetaching()
		{
			base.OnDetaching();

            AssociatedObject.GotFocus -= new RoutedEventHandler(AssociatedObject_GotFocus);
        }
	}
}